package com.qianyu.project.mapper.provider;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qianyu.project.entity.ProviderInfo;
import org.apache.ibatis.jdbc.SQL;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import java.util.Map;

/**
 * author wyh
 * Date 2021/2/4
 **/
public class LaborSubcontractProvider {
    public String getSubcontracts(Map<String, Object> map){
        return new SQL(){
            {
                SELECT("*");
                FROM("labor_subcontract ls,project_info pi,provider_info pri,emp e");
                WHERE("ls.p_id=pi.id and ls.pro_id=pri.id and ls.e_id=e.id");
                if(!StringUtils.isEmpty(map.get("startPrice")) && !StringUtils.isEmpty(map.get("entPrice"))){
                WHERE("ls.contract_amount>='"+map.get("startPrice")+"' and ls.contract_amount<='"+map.get("entPrice")+"'");
                }
                if(!StringUtils.isEmpty(map.get("id"))){
                    WHERE("ls.id='"+map.get("id")+"'");
                }
                if(!StringUtils.isEmpty(map.get("conreactName"))){
                    WHERE("ls.contract_name like '%"+map.get("conreactName")+"%'");
                }
                if(!StringUtils.isEmpty(map.get("projectName"))){
                    WHERE("pi.project_name like '%"+map.get("projectName")+"%'");
                }
                if(!StringUtils.isEmpty(map.get("providerName"))){
                    WHERE("pri.provider_name like '%"+map.get("providerName")+"%'");
                }
                if(!StringUtils.isEmpty(map.get("name"))){
                    WHERE("e.name like '%"+map.get("name")+"%'");
                }
                if(!StringUtils.isEmpty(map.get("startDate")) && !StringUtils.isEmpty(map.get("endDate"))){
                    WHERE("ls.create_date>='"+map.get("startDate")+"' and ls.create_date<='"+map.get("endDate")+"'");
                }
                if(!StringUtils.isEmpty(map.get("approveStatus"))){
                    WHERE("ls.approve_status = '"+map.get("approveStatus")+"'");
                }
            }
        }.toString();
    }


    public String getTo(String id){
        return new SQL(){
            {
                SELECT("*");
                FROM("labor_subcontract ls,project_info pi,provider_info pri,emp e");
                WHERE("ls.p_id=pi.id and ls.pro_id=pri.id and ls.e_id=e.id and ls.i='"+id+"'");

            }
        }.toString();
    }
}
